package com.david.func_test.activity

import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.BackgroundColorSpan
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.david.func_test.R

//参考链接：https://juejin.cn/post/6982466140274589709
//https://developer.android.google.cn/guide/topics/text/spans?hl=zh-cn
class SpanableTestActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_spannble_test)
        val spannableStr = SpannableString("测试事实上是事实上")
        spannableStr.setSpan(ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        spannableStr.setSpan(BackgroundColorSpan(Color.GREEN), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        spannableStr.setSpan(StyleSpan(Typeface.BOLD), 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

        findViewById<TextView>(R.id.spannable_text).text = spannableStr


        val spanBuilder = SpannableStringBuilder()
        spanBuilder.append("")
    }
}